package server;/**
import	java.util.stream.Collectors;
 * Created by IntelliJ IDEA.
 * User: Yangdx.
 * Date: 2020/5/31.
 * Time: 3:10.
 * Tags: Code, we are serious.
 */

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author
 * @create 2020-05-31 3:10
 **/
public class FindFile {
    public static ArrayList<File> getListFiles(Object obj,String fileName) {
        File directory = null;
        if (obj instanceof File) {
            directory = (File) obj;
        } else {
            directory = new File(obj.toString());
        }
        ArrayList<File> files = new ArrayList<File>();
        if(fileName.startsWith("*.")){
            if (directory.isFile() &&
                    directory.getName().endsWith(
                            fileName.substring(fileName.lastIndexOf(".")))) {
                files.add(directory);
                return files;
            } else if (directory.isDirectory()) {
                File[] fileArr = directory.listFiles();
                for (File fileOne : fileArr) {
                    files.addAll(getListFiles(fileOne, fileName));
                }
            }
        }else if (fileName.contains(".")){
            if (directory.isFile() &&
                    directory.getName().equals(fileName)) {
                files.add(directory);
                return files;
            } else if (directory.isDirectory()) {
                File[] fileArr = directory.listFiles();
                for (File fileOne : fileArr) {
                    files.addAll(getListFiles(fileOne, fileName));
                }
            }
        }else{
            if (directory.isFile()) {
                files.add(directory);
                return files;
            } else if (directory.isDirectory()) {
                File[] fileArr = directory.listFiles();
                if (fileArr != null) {
                    for (File fileOne : fileArr) {
                        files.addAll(getListFiles(fileOne, fileName));
                    }
                }

            }
        }
            return files;
    }

    public static void main(String[] args) throws IOException {
        String servletClass = "server.LagouServlet";
        servletClass = servletClass.replaceAll("\\.","\\\\");
        System.out.println(servletClass);
    }
}
